package collection.listtest;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class SortStudent {
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();
        list.add(new Student("tom",68));
        list.add(new Student("bob",34));
        list.add(new Student("ani",34));
        list.add(new Student("peter",11));
        /*
        Collections.sort(list, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int tem = o1.getAge()-o2.getAge();
                return tem==0 ? o1.getName().compareTo(o2.getName()) : tem;
            }
        });
         */
        Collections.sort(list,(o1,o2)-> o1.getAge()-o2.getAge());
        Collections.sort(list,(Student o1,Student o2)->{
            return o1.getAge()-o2.getAge();
        });
        Collections.sort(list,(o1,o2)->{
            return o1.getAge()-o2.getAge();
        });
        System.out.println("list排序后:"+list);
    }
}

class Student{
    private String name;
    private Integer age;

    public Student() {
    }

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "SortStudent{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}